package com.app.acitivty;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.app.activity.R;
import com.app.components.TopMenu;
import com.app.data.TicketItem;
import com.app.utils.ActivityTools;

public class TicketListActivity extends Activity implements OnItemClickListener {

	private ListView lvTicketList;
	private ArrayList<HashMap<String, String>> mItems = null;

	private void initView() {
		lvTicketList = (ListView) findViewById(R.id.lvTicketList);
	}

	private String[] mColumnNames = { "ticketTitle", "ticketPrice",
			"ticketStart", "ticketEnd" };

	private int[] mViewIds = { R.id.tickt_item_title, R.id.tickt_item_price,
			R.id.tickt_item_start, R.id.tickt_item_end };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ticket);
		initView();
		TopMenu topMenu = new TopMenu(this, "预定机票", new OnClickListener() {

			@Override
			public void onClick(View v) {
				TicketListActivity.this.finish();

			}
		}, R.drawable.top_button_unselect, R.drawable.top_button_selected, "",80);
		topMenu.onCreate();

		mItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 10; i++) {
			TicketItem ti = new TicketItem();
			ti.setTicketTitle("中国国航VA1854");
			ti.setTicketPrice("宁波的什么机场8点起飞");
			ti.setTicketStart("丽江的什么机场10点到达");
			ti.setTicketEnd("￥1033起");
			mItems.add(addItem(ti));
		}

		ListAdapter la = new SimpleAdapter(this, mItems,
				R.layout.ticket_list_item, mColumnNames, mViewIds);
		lvTicketList.setOnItemClickListener(this);
		lvTicketList.setAdapter(la);
		
		

	}

	public static HashMap addItem(TicketItem item) {
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("ticketTitle", item.getTicketTitle());
		map.put("ticketPrice", item.getTicketPrice());
		map.put("ticketStart", item.getTicketStart());
		map.put("ticketEnd", item.getTicketEnd());
		return map;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		ActivityTools.gotoActivity(this, TicketDetailActivity.class);
	}

}
